Skip to content

fix: period_config table prefix key schema check #17265

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

WesselAtWork
Copy link

What this PR does / why we need it:

Adds tests and a schema check to prevent a user from setting the prefix key on the period_config to a value containing a path delimiter

Which issue(s) this PR fixes:
Fixes #17232

Special notes for your reviewer:

I updated this buildCache block to be more readable to myself, if you don't like my change, I can revert with no functionality loss

for _, object := range objects {
// The s3 client can also return the directory itself in the ListObjects.
if object.Key == "" {
continue
}
ss := strings.Split(object.Key, delimiter)
if len(ss) < 2 || len(ss) > 3 {
return fmt.Errorf("invalid key: %s", object.Key)
}
if len(ss) == 2 {
t.commonObjects = append(t.commonObjects, object)
} else {
userID := ss[1]
if len(t.userObjects[userID]) == 0 {
t.userIDs = append(t.userIDs, client.StorageCommonPrefix(path.Join(t.name, userID)))
}
t.userObjects[userID] = append(t.userObjects[userID], object)
}
}

Other:

  1. I could only find examples using some_prefix_term_ in the schema_config_test.go file and could not determine if it is intentional that this field contain a path delimiter, the cache client won't be able to deal with it either way.
  2. This will effect the chunks.prefix as well. If this is intended to contain a delimiter, let me know, I can move the check to the IndexPeriodicTableConfig which should not effect the chunks.prefix
  3. Should I update the documentation as well? Will it be auto generated or do I need to update it there too?
  4. should I update the upgrade doc for this?

Checklist

  • Reviewed the CONTRIBUTING.md guide (required)
  • Documentation added
  • Tests updated
  • Title matches the required conventional commits format, see here
    • Note that Promtail is considered to be feature complete, and future development for logs collection will be in Grafana Alloy. As such, feat PRs are unlikely to be accepted unless a case can be made for the feature actually being a bug fix to existing behavior.
  • Changes that require user attention or interaction to upgrade are documented in docs/sources/setup/upgrade/_index.md
  • If the change is deprecating or removing a configuration option, update the deprecated-config.yaml and deleted-config.yaml files respectively in the tools/deprecated-config-checker directory. Example PR

@WesselAtWork WesselAtWork requested a review from a team as a code owner April 16, 2025 14:42
@CLAassistant
Copy link

CLAassistant commented Apr 16, 2025

CLA assistant check
All committers have signed the CLA.

path_prefix + "table3/user2/db.gz",
}
objectClient := newMockObjectClient(t, objectsInStorage)
prefixedClient := client.NewPrefixedObjectClient(objectClient, path_prefix)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used path_prefix here because all the references to NewPrefixedObjectClient seemed to use the PathPrefix from the configuration.
These tests should match the usage more closly now

}

// table/userid/db.gz
if len(ss) < 4 {
userID := ss[1]
if len(t.userObjects[userID]) == 0 {
t.userIDs = append(t.userIDs, client.StorageCommonPrefix(path.Join(t.name, userID)))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this use path.Join?
This might be doing some golang-fu here, but I think this should use t.name + delimiter + userID or something like that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

failed to sync index set fake for table to s3 with prefix containing more than 2 delimiters
2 participants